<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80"
      @submit="() => { this.pagination.current = 1; this.queryParams.pageNum = 1; this.getList() }"
      @reset="() => { this.pagination.current = 1; this.queryParams.pageNum = 1; this.getList() }">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="成果名称" name="name">
            <t-input v-model="queryParams.name" clearable placeholder="请输入成果名称" style="width: 240px" />
          </t-form-item>
          <t-form-item label="成果类别" name="achievementType">
            <t-select style="width: 240px" clearable v-model="queryParams.achievementType"
              :options="dict.type.achievement_type">
            </t-select>
          </t-form-item>
          <t-form-item label="研发单位" name="createCompany">
            <t-input v-model="queryParams.createCompany" clearable placeholder="请输入研发单位" style="width: 240px" />
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit">查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- <div class="btn-group-inline">
      <t-button @click="apply" variant="outline" theme="primary">
        <t-icon name="add" slot="icon"/>
        评价
      </t-button>
    </div> -->
    <t-table rowKey="id" :data="data" :columns="columns" hover :pagination="pagination" :loading="dataLoading">
      <template #name="{ row }">
        <t-link
          @click="dialog.objId = row.achievementId; dialog.achievementType = row.achievementType; dialog.header = row.name; dialog.open_review = true"
          hover="color" theme="primary">{{ row.name }}</t-link>
      </template>
      <!--      <template #evaluateStatus="{ row }">-->
      <!--        <t-tag @click="dialog.header=row.name;dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer"-->
      <!--               :theme="handleTheme(row.patentStatus, dict.type.achievement_status)" variant="light">-->
      <!--          {{ row.evaluateStatus | filterByDict(dict.type.achievement_status) }}-->
      <!--        </t-tag>-->
      <!--      </template>-->
      <template #achievementType="{ row }">
        {{ row.achievementType | filterByDict(dict.type.achievement_type) }}
      </template>
      <template #efficiency="{ row }">
        {{ row.efficiency }}万元
      </template>
      <template #op="{ row }">
        <t-button @click="updateData(row)" size="small" variant="text" class="t-button-link"
          v-if="row.createUserId === Number($store.state.user.userId)">
          <t-icon name="edit-1" slot="icon" />
          继续评价
        </t-button>
        <t-button size="small"
          @click="dialog.objId = row.achievementId; dialog.achievementType = row.achievementType; dialog.header = row.name; dialog.open_detail = true"
          variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon" />
          详情
        </t-button>
        <t-button v-if="['1', '4', null].includes(row.evaluateStatus)" theme="danger" @click="delObj(row)" size="small"
          variant="text" class="t-button-link">
          <t-icon name="delete" slot="icon" />
          删除
        </t-button>
      </template>
    </t-table>
    <evaluate-detail-dialog :objId="dialog.objId" :achievementType="dialog.achievementType" :header="dialog.header"
      :visible.sync="dialog.open_detail" v-if="dialog.open_detail">
    </evaluate-detail-dialog>
    <file-review :header="dialog.header" :achievementType="dialog.achievementType" :visible.sync="dialog.open_review"
      v-if="dialog.open_review" :objId="dialog.objId"></file-review>

  </div>
</template>

<script>
import evaluateDetailDialog from "./components/evaluate-detail-dialog.vue";
import fileReview from "../components/file-review.vue";

export default {
  name: "evaluate-my",
  dicts: ['achievement_status', 'achievement_type'],
  components: {
    evaluateDetailDialog,
    fileReview,
  },
  data () {
    return {
      dialog: {
        header: "",
        open: false,
        objId: null,
        open_approve_list: false,
        open_detail: false,
        open_achievement_detail: false,
        open_review: false,
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applyDateRange: [],
        startApplyDate: '',
        endApplyDate: '',
        evaluateStatus: '',
        achievementType: '',
        name: '',
        createCompany: '',
      },
      data: [],
      columns: [
        {
          colKey: "name",
          title: "成果名称",
          align: "center"
        },
        {
          colKey: "achievementType",
          title: "成果类别",
          align: "center"
        },
        {
          colKey: "createCompany",
          title: "研发单位",
          align: "center"
        },
        {
          colKey: "accepentDate",
          title: "验收时间",
          align: "center"
        },
        {
          colKey: "declareDeptName",
          title: "填报单位",
          align: "center"
        },
        {
          colKey: "efficiency",
          title: "总经济效益",
          align: "center"
        },
        {
          colKey: "count",
          title: "总评价次数",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 140,
          fixed: 'right'
        }],
      dataLoading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    };
  },
  created () {
    Object.assign(this.queryParams, this.handelQuery(this.queryParams, this.$route.query))
    this.getList();
  },
  methods: {
    apply () {
      this.$router.push(`/cgzh/other/evaluate/evaluate-apply/${Date.parse(new Date())}`);
    },
    getList () {
      this.dataLoading = true;
      this.$api.cgzh.evaluate.myList(this.queryParams).then(response => {
        this.data = response.rows;
        this.pagination.total = response.total;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    updateData (row) {
      this.$api.cgzh.evaluate.get(row.id).then(response => {
        this.$router.push({ path: `/cgzh/other/evaluate/evaluate-apply/${row.id}`, query: { title: `${row.name}-成果评价` } });
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    delObj (row) {
      const confirmDia = this.$dialog.confirm({
        header: "系统提示",
        body: `是否确认删除成果名称为"${row.name}"的数据项？`,
        theme: "warning",
        onConfirm: ({ e }) => {
          this.$api.cgzh.evaluate.delete(row.id).then(
            (res) => {
              this.getList();
              this.$message.success("删除成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }
          ).catch((e) => {
            this.$message.error(e.toString());
          });
        }
      });
    }
  }
};
</script>

<style scoped></style>
